<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><html lang="en">
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="../css/regist.css">
    <title>新笔趣阁_书友最值得收藏的网络小说阅读网</title>
    <script src="js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="js/login.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/login-ajax.css">
    <script type="text/javascript" src="./js/clipboard.min.js"></script>

</head>

<script>
    $(function () {
        $('#user').focus();
        //搜索框js
        $(".search-box").focus(function () {
            $(this).attr("placeholder", "");
        });
        $(".search-box").blur(function () {
            $(this).attr("placeholder", "输入需要搜索的小说");
        });

        //表单js
        //用户名
        $("#user").blur(function () {
            var regu = /^[\w\u4E00-\u9FFF]{5,20}$/;
            var re = new RegExp(regu);
            $(this).next().css('font-weight', 'bold');
            if ($(this).val() == '') {
                $(this).focus();
                $(this).next().text("该字段不允许为空").css("color", 'red');
                // $(this).parent().contents().filter(function () {
                //     return this.nodeType==3;
                // }).text("该字段不允许为空").css("color","red");
                // $('#user').parent().html();
            }  else if(re.test($(this).val())){
                $.get("http://localhost:8080/mutilAdmin","_method=checkname&u_username="+$(this).val(),function (data) {
                    if(data==1) $("#user").next().text("用户名未存在").css("color",'red');
                    if(data==2)  $("#user").next().text("用户名合法").css("color",'#72e51b');
                });

            }
            else $(this).next().text("用户名需由5-20位数字、字母、汉字、下划线组合而成").css("color", 'red');
        });
        //密码
        $("#pass").blur(function () {
            var regu = /^[\w]{6,16}$/;
            var re = new RegExp(regu);
            $(this).next().css('font-weight', 'bold');
            if ($(this).val() == '') {
                $(this).focus();
                $(this).next().text("该字段不允许为空").css("color", 'red');
            } else if (re.test($(this).val())) {
                $(this).next().text("密码合法").css("color", '#72e51b');
            } else $(this).next().text("密码需由6-16位数字、字母、下划线组合而成").css("color", 'red');
        });

        $("#pwd").blur(function () {
            var regu =/^[\w]{6,16}$/;
            var re = new RegExp(regu);
            $(this).next().css('font-weight','bold');
            if($(this).val()=='') {
                $(this).focus();
                $(this).next().text("该字段不允许为空").css("color",'red');
            }
            else if(!re.test($(this).val())){
                $(this).next().text("密码需由6-16位数字、字母、下划线组合而成").css("color",'red');
            }
            else if($(this).val()!=$('#pass').val())  $(this).next().text("两次输入的密码不一致！").css("color",'red');
            else  $(this).next().text("密码合法").css("color",'#72e51b');
        });



        //邮箱
        $("#email").blur(function () {
            var regu = /^\w+@\w+(\.\w+)+$/;
            var re = new RegExp(regu);
            $(this).next().css('font-weight', 'bold');
            if ($(this).val() == '') {
                $(this).focus();
                $(this).next().text("该字段不允许为空").css("color", 'red');
            }  else if(re.test($(this).val())){
                     $("#email").next().text("邮箱合法").css("color",'#72e51b');
            }
            else $(this).next().text("邮箱需由数字、字母、下划线和@、.组合而成").css("color", 'red');
        });

        //qq
        $("#yanzhengma").blur(function () {
            var regu = /^\d{4}$/;
            var re = new RegExp(regu);
            $(this).next().css('font-weight', 'bold');
            if ($(this).val() == '') {
                $(this).next().text();
            } else if (re.test($(this).val())) {
                $(this).next().text("验证码合法").css("color", '#72e51b');
            } else $(this).next().text("验证码需由4位数字组成").css("color", 'red');
        });

        //表单提交
        $("#buf_sub").click(function () {
            var flag = 1;
            $('#regis td span').each(function () {
                console.log($(this).css('color'));
                if ($(this).css('color') == "rgb(255, 0, 0)") flag = 2;
            });
            if($("#user").val()==""||$("#pass").val()==""||$("#email").val()==""||$("#yanzhengma").val()==""||$("#pwd").val()=="") flag=2;
            if (flag == 2) {
                alert("您还有信息没有填写正确！");
            } else {
                $.get("http://localhost:8080/reset", $('#regis').serialize(), function (result) {

                    alert("修改成功，为您跳转到主页面！");
                    setTimeout(function () {
                        window.location.href = "/index.jsp";
                    }, 1000);
                })
            }
        })


    });
</script>

<body>
    <!-- 头部开始 -->
    <header class="header">
        <!-- 头部的div用来保证缩放可以正常进行 -->
        <div class="center">
            <div class="header-div">
                <div class="header-left-one">
                    <!-- <img src="./images/all.gif" alt=""> -->
                    <a class="btnCopy" data-clipboard-text="localhost:8080">将本站设为首页</a>
                </div>
                <div class="header-left-two">
                    <a href="#">收藏新笔趣阁</a>
                </div>
                <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
                <script type="text/javascript" src="js/login.js"></script>
                <link rel="stylesheet" type="text/css" href="css/login-ajax.css">


                <div class="header-right">
                    <c:if test="${empty username}">
                        <form action="/mutilAdmin" class="header-form" id="loginForm">
                            账号：<input type="text" name="username" id="username" class="username">
                            密码：<input type="password" name="password" id="password" class="password">
                            <input type="button" value="登录" id="submit">
                            <a href="register.jsp" class="registration">用户注册</a>
                            <a href="forgetpwd.jsp" class="registration">忘记密码</a>
                        </form>
                    </c:if>
                    <c:if test="${not empty username}">
                    <span id="ajax">hi,${username}&ensp;
                        <c:if test="${type==3}">超级管理员
                            <a href="/mutilAdmin?_method=selectAdmin" class="svip">超级管理员界面&ensp;|</a>
                        </c:if>
                        <c:if test="${type==2}">管理员
                            <a href="/mutilAdmin?_method=selectAdmin" class="vip">管理员界面&ensp;|</a>
                        </c:if>
                        <c:if test="${type==1}">尊敬的用户
                            <a href='/index.jsp' class='user'>回到首页&ensp;|</a>
                        </c:if>
                    </span>
                        <a href="/BookShelf?_method=myBookShelf">我的书架&ensp;|</a>
                        <a href="forgetpwd.jsp">修改密码&ensp;|</a>
                        <a class="exit">安全退出&ensp;|</a>
                    </c:if>

                </div>
                <div class="clear"></div>
            </div>
        </div>
    </header>
    <!-- --------------------头部结束/整体开始 ----------------------->
    <!-- 新笔趣阁图标一栏 -->
    <div class="new-penguin center">
        <div id="new-penguin-div">
            <div class="image"><a href="index.jsp"><img src="./images/图标.jpg" alt=""></a></div>
            <div class="form-div">
                <form action="/mutilfind" class="form">
                    <input type="search" class="search-box" name="u_username" placeholder="输入需要搜索的内容">
                    <input type="hidden" name="_method" value="searchbyab">
                    <input type="submit" value="搜索" class="submit-search">
                </form>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <!-- 标题 -->
    <div class="title center">
        <div class="title-div">
            <!-- <a href="#">首页</a>
            <a href="#">永久书架</a>
            <a href="#">玄幻奇幻</a>
            <a href="#">武侠仙侠</a>
            <a href="#">都市言情</a>
            <a href="#">历史军事</a>
            <a href="#">科幻灵异</a>
            <a href="#">网游竞技</a>
            <a href="#">女频频道</a>
            <a href="#">完本小说</a>
            <a href="#">排行榜单</a>
            <a href="#">临时书架</a> -->
            <ul>
                <li><a href="index.jsp">首页</a></li>
                <li><a href="/BookShelf?_method=myBookShelf">永久书架</a></li>
                <li><a href="fantasy.jsp">玄幻奇幻</a></li>
                <li><a href="wxxx.jsp">武侠仙侠</a></li>
                <li><a href="romance.jsp">都市言情</a></li>
                <li><a href="historymilitary.jsp">历史军事</a></li>
                <li><a href="science.jsp">科幻灵异</a></li>
                <li><a href="olgame.jsp">网游竞技</a></li>
                <li><a href="femate.jsp">女频频道</a></li>
                <li><a href="mutilfind?_method=finishbook">完本小说</a></li>
                <li><a href="mutilBook?_method=topBook">排行榜单</a></li>
                <li><a href="/BookShelf?_method=tempBookShelf">临时书架</a></li>
            </ul>
        </div>
        <div class="clear"></div>
    </div>
    <!-- 标题结束 -->
    <!-- 主体部分 -->
    <div class="center">
        <form id="regis" method="POST">
            <!-- <form action="#"> -->
            <table>
                <caption>
                    <h3>修改密码</h3>
                </caption>
                <tr>
                    <td>用户名</td>
                    <td>
                        <input type="text" id="user" name="username">
                        <spaan></spaan>
                    </td>
                </tr>
                <tr>
                    <td>Email</td>
                    <td>
                        <input type="email" name="email" id="email">
                        <span></span>
                        <input type="button" value="发送验证码" id="send" >
                        <span id="span"></span>
                    </td>
                </tr>
                <tr>
                    <td>邮箱验证码</td>
                    <td>
                        <input type="text" name="Vcode" id="yanzhengma">
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" id="pass" name="password">
                        <span>请输入长度不少于六位的密码</span>
                    </td>
                </tr>
                <tr>
                    <td>重复密码</td>
                    <td>
                        <input type="password" name="pwd" id="pwd">
                        <span>请再次输入密码</span>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" class="buf_sub" id="buf_sub" value="提交">
                        <span>${msg}</span>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <tfoot>
        <div class="f_style">
            <div class="f_last">
                <p>本站所有小说为转载作品，所有章节均由网友上传，转载至本站只是为了宣传本书让更多读者欣赏。</p>
                <p>Copyright &copy; 2015&nbsp;新笔趣阁&nbsp;All Right Reserved.</p>
            </div>
        </div>
    </tfoot>
</body>
<script src="/js/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $(function () {
        $("#send").click(function (){
            var email=$("#email").val();
            var username=$("#user").val();
            $.post(
                "/sendVerification",
                "email="+email+"&username="+username,
                function (data){
                    $("#span").text(data)
                },"text"
            )
        })
        $(".search-box").focus(function () {
            $(this).attr("placeholder", "");
        })
        $(".search-box").blur(function () {
            $(this).attr("placeholder", "输入需要搜索的小说");
        })
        $("#buf_sub").click(function () {
            var err_type;
            var usernameText = $("#user").val();
            console.log(usernameText);
            var usernamePatt = /^[a-z0-9]{5,20}$/;
            if (!(usernameText == null)) {
                err_type = 1;
                $("#msg").text("用户名密码不能为空");
                return flase;
            }
            if (!usernamePatt.test(usernameText)) {
                err_type = 1;
                // 1代表
                $("#msg").text("用户名不合法");
                return flase;
            }
            var passwordText = $("#pass").val();
            var passwordPatt = /^[a-z0-9_-]{6,18}$/;
            if (!(passwordText == null)) {
                err_type = 1;
                $("#msg").text("用户名密码不能为空");
                return flase;
            }
            if (!passwordPatt.test(passwordText)) {
                err_type = 3;
                // 1代表
                $("#msg").text("密码不合法");
                return flase;
            }
            var passwordCon = $("#pwd").val();
            if (!(passwordCon == null)) {
                err_type = 4;
                $("#msg").text("重复密码不能为空");
                return flase;
            }
            if (passwordCon != passwordText) {
                err_type = 5;
                $("#msg").text("两次输入密码不一致");
                return flase;
            }
            var emailText = $("#email").val();
            var emailPatt =
                /^[\u4e00-\u9fa5a-zA-Z\d]+([-_.][\u4e00-\u9fa5A-Za-z\d]+)*@([\u4e00-\u9fa5A-Za-z\d]+[-.]){1,2}[\u4e00-\u9fa5A-Za-z\d]{2,5}$/g;
            if (!(emailText == null)) {
                err_type = 6;
                $("#msg").text("邮箱不能为空");
                return flase;
            }
            if (!emailPatt.test(emailText)) {
                err_type = 7;
                $("#msg").text("邮箱格式错误");
                return flase;
            }
            $("#msg").text("");
        })
    })
</script>

</html>